﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserMaintenance.aspx.cs" Inherits="PMP.Maintenance.UserMaintenance" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>User Maintenance</title>
    <style type="text/css">
        .style1
        {
            width: 58%;
        }
        .style2
        {
            text-align: right;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <table class="style1">
            <tr>
                <td class="style2">
                    Team:</td>
                <td>
                    <asp:DropDownList ID="ddlTeams" runat="server" 
                        DataSourceID="SqlDataSourceTeams" DataTextField="team" DataValueField="team" 
                        Height="25px" Width="200px">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceTeams" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>" 
                        ProviderName="<%$ ConnectionStrings:LocalConnectionString.ProviderName %>" 
                        SelectCommand="SELECT top 1 'TM' [team] FROM [usr]
union
SELECT DISTINCT [team] FROM [usr] ORDER BY [team]">
                    </asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    User Name:</td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" Height="25px" Width="200px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Emai:</td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server" Height="25px" Width="200px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Manager:</td>
                <td>
                    <asp:DropDownList ID="ddlManagers" runat="server" 
                        DataSourceID="SqlDataSourceLeaders" DataTextField="usr_name" 
                        DataValueField="id" Height="25px" Width="200px">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSourceLeaders" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>" 
                        ProviderName="<%$ ConnectionStrings:LocalConnectionString.ProviderName %>" 
                        SelectCommand="SELECT '' [usr_name], 0 [id] FROM [usr]
union
SELECT [usr_name], [id] FROM [usr] ORDER BY [usr_name]">
                    </asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" 
                        style="height: 26px" Text="Add" />
                </td>
                <td>
                    <asp:Button ID="btnClear" runat="server" onclick="btnClear_Click" 
                        Text="Clear" />
                </td>
            </tr>
        </table>
        <br />
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="id" DataSourceID="SqlDataSourceUsers" 
            ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="team" HeaderText="team" SortExpression="team" />
                <asp:BoundField DataField="usr_name" HeaderText="usr_name" 
                    SortExpression="usr_name" />
                <asp:BoundField DataField="password" HeaderText="password" 
                    SortExpression="password" />
                <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
                <asp:BoundField DataField="mgr_id" HeaderText="mgr_id" 
                    SortExpression="mgr_id" />
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                    ReadOnly="True" SortExpression="id" />
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSourceUsers" runat="server" 
            ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>" 
            DeleteCommand="DELETE FROM [usr] WHERE [id] = ?" 
            InsertCommand="INSERT INTO [usr] ([team], [usr_name], [password], [email], [mgr_id], [id]) VALUES (?, ?, ?, ?, ?, ?)" 
            ProviderName="<%$ ConnectionStrings:LocalConnectionString.ProviderName %>" 
            SelectCommand="SELECT [team], [usr_name], [password], [email], [mgr_id], [id] FROM [usr] ORDER BY [team], [usr_name]" 
            UpdateCommand="UPDATE [usr] SET [team] = ?, [usr_name] = ?, [password] = ?, [email] = ?, [mgr_id] = ? WHERE [id] = ?">
            <DeleteParameters>
                <asp:Parameter Name="id" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="team" Type="String" />
                <asp:Parameter Name="usr_name" Type="String" />
                <asp:Parameter Name="password" Type="String" />
                <asp:Parameter Name="email" Type="String" />
                <asp:Parameter Name="mgr_id" Type="Int32" />
                <asp:Parameter Name="id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="team" Type="String" />
                <asp:Parameter Name="usr_name" Type="String" />
                <asp:Parameter Name="password" Type="String" />
                <asp:Parameter Name="email" Type="String" />
                <asp:Parameter Name="mgr_id" Type="Int32" />
                <asp:Parameter Name="id" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
